package com.tuanzi.webtalk.controller;

import com.tuanzi.result.ResultVo;
import com.tuanzi.webtalk.domain.User;
import com.tuanzi.webtalk.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 雄关漫道真如铁，而今迈过从头越
 **/

@Controller
public class LoginController {

    @Resource
    private LoginService loginService;

    /**
     * 这里写一个登录页面
     */
    @RequestMapping(value = "/user/login")
    @ResponseBody
    public ResultVo login(HttpSession session, String username, String password){
        User user = loginService.login(username, password);
        ResultVo resultVo = new ResultVo();
        resultVo.setOk(false);
        resultVo.setMess("用户名或密码错误！！！");
        if (user != null){
            session.setAttribute("user",user);
            resultVo.setOk(true);
        }
        return resultVo;
    }


}
